﻿<template>
  <div>
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                icon: 'ant-design:delete-outlined',
                color: 'error',
                popConfirm: {
                  title: '是否确认强制下线',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { sysOnlineUserPage, sysOnlineUserForceExist } from '/@/api/sys/onlineUser';

  import { columns, searchFormSchema } from './onlineUser.data';

  export default defineComponent({
    name: 'SysOnlineUserManagement',
    components: { BasicTable, TableAction },
    setup() {
      const [registerTable, { reload }] = useTable({
        title: '在线用户列表',
        api: sysOnlineUserPage,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          fixed: undefined,
        },
      });

      const handleDelete = async (record: Recordable) => {
        console.log(record);
        await sysOnlineUserForceExist(record);
        handleSuccess();
      };

      const handleSuccess = () => {
        reload();
      };

      return {
        registerTable,
        handleDelete,
        handleSuccess,
      };
    },
  });
</script>
